//
//  CXLStatusRetweetCell.swift
//  weibo1990
//
//  Created by 曹晓龙 on 15/10/22.
//  Copyright © 2015年 曹晓龙. All rights reserved.
//

import UIKit
import FFLabel
/// 转发微博视图
class CXLStatusRetweetCell: StatusCell {

    
    /// 单条微博数据视图模型
    override var statusViewModel:StatusViewModel?{
        
        didSet{
            //更新配图约束
            
            let text = CXLEmoticonManager.shareEmoticionManager.emticonText(statusViewModel?.retweetedText ?? "", font: retweetedLbl.font)
            
            retweetedLbl.attributedText = text
            
            let offset = (statusViewModel?.pictureUrls?.count ?? 0) == 0 ? 0 : statusCellMargin
            
            pictureView.snp_updateConstraints { (make) -> Void in
                make.top.equalTo(retweetedLbl.snp_bottom).offset(offset)
            }
        }
    }
    

    //MARK: - 懒加载
    /// 背景button
    private lazy var backBtn: UIButton = {
       
        let btn = UIButton()
        
        btn.backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        
        return btn
    }()

    /// 转发微博文字
    private lazy var retweetedLbl:FFLabel = FFLabel(titleText: "转发微博", textFont: 14, color: UIColor.darkGrayColor(), screenInset: statusCellMargin)
}


extension CXLStatusRetweetCell {
    
    override func setupUI() {
       
        super.setupUI()
        
        //添加控键
        contentView.insertSubview(backBtn, belowSubview: pictureView)
        contentView.insertSubview(retweetedLbl, aboveSubview: backBtn)
        
        //自动布局
        backBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(titleLbl.snp_bottom).offset(statusCellMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(statusCellBottom.snp_top).offset(statusCellMargin)
        }
        
        retweetedLbl.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(titleLbl.snp_bottom).offset(statusCellMargin)
            make.left.equalTo(contentView.snp_left).offset(statusCellMargin)
        }
        
        //配图界面
        pictureView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentView.snp_left).offset(statusCellMargin)
            make.top.equalTo(retweetedLbl.snp_bottom).offset(statusCellMargin)
            make.width.equalTo(300)
            make.height.equalTo(90)
        }
        
        // 设置label 代理
        retweetedLbl.labelDelegate = self
    }
}